//
//  DetailViewController.m
//  IchartjsDemo
//
//  Created by wanglong wang on 13-1-15.
//  Copyright (c) 2013年 __MyCompanyName__. All rights reserved.
//

#import "DetailViewController.h"

@interface DetailViewController ()

@end

@implementation DetailViewController
@synthesize activityIndicator;
@synthesize charttype;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    //创建UIWebView
    UIWebView *WebView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 400)];
//    [WebView setUserInteractionEnabled:YES];
//    WebView.scalesPageToFit =YES;
//    [WebView setBackgroundColor:[UIColor clearColor]];
//    [WebView setOpaque:NO];//使网页透明
    
    WebView.delegate = self;
    if(charttype==0){
        NSString *path = [[NSBundle mainBundle] pathForResource:@"mianji_chart.html" ofType:nil];
        [WebView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath: path]]];
        
    }else{
        NSString *path = [[NSBundle mainBundle] pathForResource:@"zhuzhuang_chart.html" ofType:nil];
        [WebView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath: path]]];
        
    }
    
    
//    NSString *path = @"http://www.youku.com";
//    NSURL *url = [NSURL URLWithString:path];
//    [WebView loadRequest:[NSURLRequest requestWithURL:url]];
    
    
    //创建UIActivityIndicatorView背底半透明View   
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
    [view setTag:103];
    [view setBackgroundColor:[UIColor blackColor]];
    [view setAlpha:0.8];
    [self.view addSubview:view];
    
    activityIndicator = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 32.0f, 32.0f)];
    [activityIndicator setCenter:view.center];
    [activityIndicator setActivityIndicatorViewStyle:UIActivityIndicatorViewStyleWhite];
    [view addSubview:activityIndicator];
    [self.view addSubview:WebView];
    
    }
//开始加载数据
- (void)webViewDidStartLoad:(UIWebView *)webView {   
    [activityIndicator startAnimating];      
}

//数据加载完
- (void)webViewDidFinishLoad:(UIWebView *)webView {
    [activityIndicator stopAnimating];   
    UIView *view = (UIView *)[self.view viewWithTag:103];
    [view removeFromSuperview];
    
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end
